#ifndef ___RSLIB_MATHX___
#define ___RSLIB_MATHX___
 
 
 
//---INCLUDE
//------------------->
#include <RSLib_OLD\Types.hpp>
#include <math.h>
#include <float.h>
 
 
 
namespace RSLib {
namespace Math {
 
 

//---CONSTANTS
//----------------------------------------------------------->
const FLT32 DoublePiGreco = 6.2831853071795864769252867665590f;
const FLT32 PiGreco = 3.1415926535897932384626433832795f;
const FLT32 HalfPiGreco = 1.5707963267948966192313216916398f;

#define RS_DOUBLEPIGRECO   6.2831853071795864769252867665590f
#define RS_PIGRECO         3.1415926535897932384626433832795f
#define RS_HALFPIGRECO     1.5707963267948966192313216916398f
#define RS_EPSILON32       1.192092896e-07F
#define RS_FLT32_EPSILON   1.192092896e-07F
#define RS_FLT32_MAX       3.402823466e+38F
#define RS_FLT32_MIN       1.175494351e-38F

 
 
//---MATH FUNCTION
//-------------------------------------------------------------------------------------------->
inline FLT32 ReciprocalSquareRoot(FLT32 a)                              {return 1.0f/sqrtf(a);}
inline FLT32 LogBase(FLT32 base,FLT32 value)                            {return logf(value)/logf(base);}
inline FLT32 Sign(FLT32 f)
{
   if (f == 0) return 0;
   else if (f > 0) return 1;
   else return -1;
//{return SEEAS(DWORD,f)&0x80000000 ? -1.0f : 1.0f;}
}
 
 
template <class T> __forceinline bool IsNonZero(const T& a)                   {return a != T(0);}
template <class T> __forceinline bool IsZero(const T& a)                      {return a == T(0);}
template<class T> __forceinline T Square( T const &a )                        {return a * a;}
template <class T> __forceinline T Lerp(FLT32 x, T const &A, T const &B )     {return A + (B - A) * x;}
 
template <class T> __forceinline bool Bounded(const T& val, const T& min, const T& max)
{
   return (val >= min) && (val <= max);
}
template <class T> __forceinline bool Equals(const T& a, const T& b, FLT32 tollerance = FLT_EPSILON)
{
   return Abs(a - b) <= tollerance;
}
template <class T> __forceinline T ClampedLerp(const FLT32 x, T const &A, T const &B)
{
   if (x<0) return A;
   else if (x>1) return B;
   else return A + (B - A) * x;
}
template <class T> __forceinline VOID Swap(T& x, T& y )
{
   T temp = x;
   x = y;
   y = temp;
}
template <class T> __forceinline T Clamp(const T& val,const T& min,const T& max)
{
   return (((val) > (max)) ? (max) : (((val) < (min)) ? (min) : (val)));
}
 
inline FLT32 Abs(FLT32 f)           {return fabsf(f);}
inline FLT32 Floor(FLT32 f)         {return floorf(f);}
inline FLT32 Ceil(FLT32 f)          {return ceilf(f);}
inline FLT32 Mod(FLT32 f,FLT32 q)   {return fmodf(f,q);}
inline FLT32 SquareRoot(FLT32 f)    {return sqrtf(f);}
 
inline FLT32 Exp(FLT32 f)           {return expf(f);}
inline FLT32 LogE(FLT32 f)          {return logf(f);}
inline FLT32 Log10(FLT32 f)         {return log10f(f);}
inline FLT32 Pow(FLT32 f,FLT32 exp) {return powf(f,exp);}
 
inline FLT32 Cos(FLT32 angle)       {return cosf(angle);}
inline FLT32 Sin(FLT32 angle)       {return sinf(angle);}
inline FLT32 Tan(FLT32 angle)       {return tanf(angle);}
inline FLT32 Acos(FLT32 rad)        {return acosf(rad);}
inline FLT32 Asin(FLT32 rad)        {return asinf(rad);}
inline FLT32 Atan(FLT32 rad)        {return atanf(rad);}
inline FLT32 Atan(FLT32 x,FLT32 y)  {return atan2(x,y);}
 
inline FLT32 Sinh(FLT32 angle)      {return sinhf(angle);}
inline FLT32 Cosh(FLT32 angle)      {return coshf(angle);}
inline FLT32 Tanh(FLT32 angle)      {return tanhf(angle);}
 
inline FLT32 DegToRad(FLT32 degs)   {return degs/180.0f * RS_PIGRECO;}
inline FLT32 RadToDeg(FLT32 rads)   {return rads/RS_PIGRECO * 180.0f;}
 
inline FLT32 AngleFromSinCos(FLT32 sin,FLT32 cos)
{
   FLT32 angle = Asin(sin);
   if (cos > 0) return angle;
   else return PiGreco - angle;
}
 
 
 
}//namespace Math
}//namespace RSLib
 
 
 
#endif//___RSLIB_MATH___